package com.yfuxdeer.youchat.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

import com.yfuxdeer.youchat.client.Client;
import com.yfuxdeer.youchat.utils.Store;

public class ClientService extends Service {
    private static final String TAG = ClientService.class.getSimpleName();
    private Client client;
    private Store store = Store.getInstance();


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                client = new Client(ClientService.this);
                Log.e(TAG, "client : " + client);
                if (client != null) {
                    Log.e(TAG, "Socket是好的: ");
                    store.setClient(client);
                    client.start();
                }

            }
        }).start();
        return super.onStartCommand(intent, flags, startId);
    }
}
